package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.LiangSortItem;
import com.sam.im.heiqun.uis.beans.GetVipNumBean;

import java.util.List;

/**
 * Created by wangguodong on 2017/8/21.
 */

public class LiangIMAdapter extends RecyclerView.Adapter <LiangIMAdapter.ViewHold>{
    private static final String TAG = "LiangSortAdapter";
    private Context mContext ;
    private List<GetVipNumBean.ListBean> datas ;

    private OnBuyClickLisener onBuyClickLisener ;
    public interface OnBuyClickLisener{
        void OnBuy(int pos);
    }
    public void setOnBuyClickLisener(OnBuyClickLisener onBuyClickLisener){
        this.onBuyClickLisener = onBuyClickLisener ;
    }

    public LiangIMAdapter(Context mContext, List<GetVipNumBean.ListBean> datas){
        this.mContext = mContext ;
        this.datas = datas ;
    }

    @Override
    public LiangIMAdapter.ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View headView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_liang_im, parent, false);
        return new ViewHold(headView);
    }

    @Override
    public void onBindViewHolder(LiangIMAdapter.ViewHold holder, final int position) {
        GetVipNumBean.ListBean listBean = datas.get(position);

        holder.txt_name.setText(listBean.getNum()+"（￥："+listBean.getPrice()+"）");

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        holder.txt_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null!=onBuyClickLisener)onBuyClickLisener.OnBuy(position);
            }
        });

//        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date d1=new Date(Long.parseLong(listBean.getCreateTime()));
//        String t1=format.format(d1);
//        holder.txt_time.setText(t1);

    }

    @Override
    public int getItemCount() {
        return null==datas?0:datas.size();
    }

    class ViewHold extends RecyclerView.ViewHolder{

        TextView txt_name ;
        TextView txt_buy ;

        View view ;

        public ViewHold(View itemView) {
            super(itemView);
            view = itemView ;

            txt_name = (TextView) itemView.findViewById(R.id.txt_name);
            txt_buy = (TextView) itemView.findViewById(R.id.txt_buy);
        }
    }

}
